<?php

/**
 * This is the model class for table "Reservation".
 *
 * The followings are the available columns in table 'Reservation':
 * @property string $id
 * @property string $itemId
 * @property string $ownerId
 * @property string $quantity
 *
 * Related records:
 * @property Item $item
 * @property User $owner
 */
class Reservation extends ActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Reservation the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{Reservation}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		return array(
			array('itemId, ownerId, quantity', 'required'),
			array('itemId, ownerId, quantity', 'length', 'max'=>10),
			array('id, itemId, ownerId, quantity', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		return array(
			'item' => array(self::BELONGS_TO, 'Item', 'itemId'),
			'owner' => array(self::BELONGS_TO, 'User', 'ownerId'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => Yii::t('label', 'Id'),
			'itemId' => Yii::t('label', 'Item'),
			'ownerId' => Yii::t('label', 'Owner'),
			'quantity' => Yii::t('label', 'Quantity'),
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('itemId',$this->itemId,true);
		$criteria->compare('ownerId',$this->ownerId,true);
		$criteria->compare('quantity',$this->quantity,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}